{{define "cms/role_edit.html"}}
{{ template "header" . }}

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-title">
        权限管理 / 角色管理 / 编辑角色
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="form-horizontal">
                        <input type="hidden" name="token" value="{{ .token }}">
                        <input type="hidden" placeholder="" name="id" value="{{.obj.ID}}" class="form-control">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">角色名称：</label>
                            <div class="col-sm-3">
                                <input type="text" placeholder="" name="name" value="{{.obj.Name}}" class="form-control" required> <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-3">
                                <button class="btn btn-sm btn-primary" onclick="edit_role()">修 改</button>
                                <a href="/role" class="btn btn-sm btn-white">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


{{ template "footer" . }}
<script>
    function edit_role(){
        var token = $("input[name='token']").val();
        var id = $("input[name='id']").val();
        var name = $("input[name='name']").val();
        if(name === ""){
            layer.msg("角色名称不能为空", {icon: 2, time: 1200, title: "提示"});
            return;
        }

        $.post("/roleedit", {id:id, name:name, token: token},function (res) {
            var jsonData = $.parseJSON(res);
            if(jsonData.status !== 200 && jsonData.status !== 20023){
                if(jsonData.status !== 20007) {
                    $("input[name='token']").val(jsonData.data);
                }
                layer.msg(jsonData.message, {icon: 2, time: 1200, title: "提示"});
            } else if(jsonData.status === 20023) {
                window.location.href = "/nopermission";
            } else {
                layer.msg(jsonData.message, {
                    icon: 1,
                    time: 1000,
                    title: "提示",
                    end:function () {
                        window.location.href = "/role";
                    }
                });
            }
        });
    }
</script>
{{end}}